package com.anyou.mall.goo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.anyou.mall.goo.vo.GoodsSuitDetailsVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.goo.domain.GoodsSuit;
import com.anyou.mall.goo.service.IGoodsSuitService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 套装商品Controller
 *
 * @author gaochaohao
 * @date 2022-04-02
 */
@Api(tags = "套装商品")
@RestController
@RequestMapping("/goo/goodsSuit")
public class GoodsSuitController extends BaseController
{
    @Autowired
    private IGoodsSuitService goodsSuitService;

    /**
     * 查询套装商品列表
     */
    @ApiOperation("查询套装商品列表")
    @PreAuthorize("@ss.hasPermi('goo:goodsSuit:list')")
    @GetMapping("/list")
    public TableDataInfo<List<GoodsSuit>> list(GoodsSuit goodsSuit)
    {
        startPage();
        List<GoodsSuit> list = goodsSuitService.selectGoodsSuitList(goodsSuit);
        return getDataTable(list);
    }

    /**
     * 导出套装商品列表
     */
    @ApiOperation("导出套装商品列表")
    @PreAuthorize("@ss.hasPermi('goo:goodsSuit:export')")
    @Log(title = "套装商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsSuit goodsSuit)
    {
        List<GoodsSuit> list = goodsSuitService.selectGoodsSuitList(goodsSuit);
        ExcelUtil<GoodsSuit> util = new ExcelUtil<GoodsSuit>(GoodsSuit.class);
        util.exportExcel(response, list, "套装商品数据");
    }

    /**
     * 获取套装商品详细信息
     */
    @ApiOperation("获取套装商品详细信息")
    @PreAuthorize("@ss.hasPermi('goo:goodsSuit:query')")
    @GetMapping(value = "/{goodsSuitId}")
    public ApiResult<GoodsSuitDetailsVo> getInfo(@PathVariable("goodsSuitId") Long goodsSuitId)
    {
        return ApiResult.success(goodsSuitService.selectGoodsSuitByGoodsSuitId(goodsSuitId));
    }

    /**
     * 新增套装商品
     */
    @ApiOperation("新增套装商品")
    @PreAuthorize("@ss.hasPermi('goo:goodsSuit:add')")
    @Log(title = "套装商品", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody GoodsSuit goodsSuit)
    {
        return ApiResult.success(goodsSuitService.insertGoodsSuit(goodsSuit));
    }

    /**
     * 修改套装商品
     */
    @ApiOperation("修改套装商品")
    @PreAuthorize("@ss.hasPermi('goo:goodsSuit:edit')")
    @Log(title = "套装商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody GoodsSuit goodsSuit)
    {
        return ApiResult.success(goodsSuitService.updateGoodsSuit(goodsSuit));
    }

    /**
     * 删除套装商品
     */
    @ApiOperation("删除套装商品")
    @PreAuthorize("@ss.hasPermi('goo:goodsSuit:remove')")
    @Log(title = "套装商品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{goodsSuitIds}")
    public ApiResult remove(@PathVariable Long[] goodsSuitIds)
    {
        return ApiResult.success(goodsSuitService.deleteGoodsSuitByGoodsSuitIds(goodsSuitIds));
    }

    /**
     * 修改套装商品状态
     */
    @ApiOperation("修改套装商品状态")
    @PreAuthorize("@ss.hasPermi('goo:goodsSuit:disable')")
    @Log(title = "套装商品", businessType = BusinessType.UPDATE)
    @PostMapping("/EnableStatus/{goodsSuitId}")
    public ApiResult updateEnableStatus(@PathVariable("goodsSuitId") Long goodsSuitId) {
        return goodsSuitService.updateEnableStatus(goodsSuitId);
    }
}
